package com.run.web.backend;


import com.run.model.EbComment;
import com.run.service.CommentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.List;

@Controller
@RequestMapping("/comment")
public class CommentController {
    @Autowired
    private CommentService commentService;

    @RequestMapping("/list")
    public String list(Model model,
                       @RequestParam(value = "page",defaultValue = "1") int page,
                       @RequestParam(value = "pageSize",defaultValue = "3") int pageSize){
        System.out.println("进入comment");

        List<EbComment> ebComments = commentService.list(page,pageSize);
        model.addAttribute("ebComment",ebComments);
        return "manage/guestbook";
    }

    @RequestMapping("/to_ecid")
    public String toecid(Model model, @RequestParam("ecid")int ecid){
        System.out.println("点击修改了。ecid="+ecid);
        EbComment ebComment = commentService.selectOne(ecid);
        model.addAttribute("ebComment",ebComment);
        System.out.println(model.addAttribute("ebComment",ebComment));
        return  "manage/guestbook-modify";
    }

    @RequestMapping("/ecit")
    public String ecit(EbComment ebComment){
        Integer reault = commentService.updateOrder(ebComment);
        if(reault<1){
            return "manage/manage-error";
        }
        return "manage/manage-result";
    }

    @RequestMapping("/delet")
    public String delet(Model model,@RequestParam("ecid")int ecid){
        int result  = commentService.deltOrder(ecid);
        model.addAttribute("ebComment",result);
        if (result<1){
            return "manage/manage-error";
        }
        return "manage/manage-result";
    }

}
